import instacne from "../request";
import type { Ref } from "vue";

/**
 *  优惠券列表  查询  /coupon/list
 *
 */
interface ICouponListParams {
  name?: string;
  // orderSn: string;
  pageNum: number;
  pageSize: number;
  type?: number;
  couponId: number;
  id?: number;
  // useStatus: number;
}
interface ICouponListItem {
  amount: number;
  code: string;
  count: number;
  enableTime: string;
  endTime: string;
  id: number;
  // memberLevel: number;
  memberLevel: string;
  // minPoint: number;
  minPoint: string;
  name: string;
  note: string;
  perLimit: number;
  platform: number;
  // publishCount: number;
  publishCount: string;
  // receiveCount: number;
  receiveCount: string;
  startTime: string;
  type: number;
  useCount: number;
  useType: number;
}
interface ICouponListRes {
  list: ICouponListItem[];
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
}
const couponList = (data?: ICouponListParams): Promise<ICouponListRes> => {
  return instacne.get("/coupon/list", {
    params: data,
  });
};

/**
 *  优惠券列表  查看 领取详情
 */
const couponDetail = (data: ICouponListParams) => {
  return instacne.get(`/coupon/${data.id}`, data);
};

/**
 *  优惠券列表  查看 领取记录下面表格
 */
const couponHistory = (data: ICouponListParams) => {
  return instacne.get(`/couponHistory/list`, { params: data });
};

/**
 *  优惠券列表  编辑
 */
const couponEdit = (data: ICouponListItem): Promise<ICouponListItem> => {
  return instacne.post(`/coupon/update/${data.id}`, data);
};

/**
 *  优惠券列表  删除
 */
const couponDel = (data: ICouponListParams) => {
  return instacne.post(`/coupon/delete/${data.id}`, data);
  // return instacne.post(`/coupon/delete?ids=${data}`);
};
// const getControllerdel = (data: number) => {
//   return instacne.post(`/home/advertise/delete?ids=${data}`);
// };

/**
 *  优惠券列表  添加
 */
const couponCreate = (data: ICouponListItem): Promise<ICouponListItem> => {
  return instacne.post("/coupon/create", data);
};

export {
  couponList,
  couponDetail,
  couponEdit,
  couponHistory,
  couponDel,
  couponCreate,
};
export type { ICouponListItem, ICouponListParams, ICouponListRes };
